
import java.util.Scanner;
import java.util.ArrayList;

public class Main6{

    private static Scanner in;

    public static void main(String[] args) {
        in = new Scanner(System.in);
        int n;
        int m;
        while (true) {
            String s = in.next();
            int flag = 0;
            ArrayListGeneralStack<?> stack;
            switch (s) {
                case "Integer":
                    Integer sumI=0;
                    n = in.nextInt();
                    m = in.nextInt();
                    stack = new ArrayListGeneralStack<Integer>(n);
                    System.out.println("Integer Test");
                    for (int i = 0; i < n; i++) {
                        System.out.println("push:" + stack.push(in.nextInt()));
                    }
                    for (int i = 0; i < m; i++) {
                        System.out.println("pop:" + stack.pop());
                    }
                     for (int i = 0; i < stack.size(); i++) {
                        Integer j = (Integer) stack.getArrayList().get(i);
                        sumI += j;
                    }
                    System.out.println(stack);
                        System.out.println("sum="+sumI);
                    System.out.println(stack.getClass().getInterfaces()[0]);
                    break;
                case "Double":
                    n = in.nextInt();
                    m = in.nextInt();
                    Double sumD = 0.0;
                    stack = new ArrayListGeneralStack<Double>(n);
                    System.out.println("Double Test");
                    for (int i = 0; i < n; i++) {
                        System.out.println("push:" + stack.push(in.nextDouble()));
                    }
                    for (int i = 0; i < m; i++) {
                        System.out.println("pop:" + stack.pop());
                    }
                   
                    for (int i = 0; i <stack.size(); i++) {
                        Double j = (Double) stack.getArrayList().get(i);
                        sumD += j;
                    }
                        System.out.println(stack);
                        System.out.println("sum="+sumD);
                    System.out.println(stack.getClass().getInterfaces()[0]);
                    break;
                case "Car":
                    n = in.nextInt();
                    m = in.nextInt();
                    stack = new ArrayListGeneralStack<Car>(n);
                    System.out.println("Car Test");
                    for (int i = 0; i < n; i++) {
                        System.out.println("push:" + stack.push(new Car(in.nextInt(), in.next())));
                    }
                    for (int i = 0; i < m; i++) {
                        System.out.println("pop:" + stack.pop());
                    }
                    if(m>=n){
                            System.out.println(stack);
                            System.out.println("null");
                    }else {
                            System.out.println(stack);
                            for (int i = stack.size()-1; i >=0; i--) {
                                System.out.println(((Car)stack.getArrayList().get(i)).getName());
                         }
                    }
                    System.out.println(stack.getClass().getInterfaces()[0]);
                    break;
                case "quit":
                    flag = 1;
                    break;
                default:
                    break;
            }
            if (flag == 1) {
                break;
            }
        }

    }
}

interface GeneralStack<T> {

    public T push(Object item);

    public T pop();

    public T peek();

    public boolean empty();

    public int size();
}

class ArrayListGeneralStack<T> implements GeneralStack<T> {

    private ArrayList<T> List;
    private final int n;

    public ArrayListGeneralStack(int n) {
        List = new ArrayList<>();
        this.n = n;
    }

    public T push(Object item) {
        if (item == null) {
            return null;
        }
        if (List.size() >= n) {
            return null;
        }
        List.add((T) item);
        return (T) item;
    }

    public T pop() {
        if (List.size() == 0) {
            return null;
        }
        T a;
        a = List.get(List.size() - 1);
        List.remove(List.size() - 1);
        return a;
    }

    public T peek() {
        if (List.size() == 0) {
            return null;
        }
        return List.get(List.size() - 1);
    }

    public boolean empty() {
        return List.size() == 0;
    }

    public int size() {
        return List.size();
    }

    public ArrayList<T> getArrayList() {
        return List;
    }

    public String toString() {
        return List.toString();
    }
}

class Car {

    private int id;
    private String name;

    public Car(int id, String name) {
        this.id = id;
        this.name = name;
    }

    @Override
    public String toString() {
        return "Car [" + "id=" + id + ", name=" + name + ']';
    }

    public int getId() {
        return id;
    }

    public void setId(int id) {
        this.id = id;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

}
